<div class="modal-header">
    <span class="modal-title"><i class="fas fa-info-circle mr-1"></i>{:lang('v_user')} {:lang('shopv_discount')}</span>
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
    <form name="group_discount" id="group_discount">
        <input type="hidden" name="lang" value="{:input('lang')}">
        <input type="hidden" name="id" value="{:input('id')}">
        {volist name="auth_group" id="groupRs"}
            {php}$discount = '';{/php}
            {foreach $discount_rs_arr as $i=>$val}
                {if $val[0] eq $groupRs.id}
                    {php}$discount = $val[1];{/php}
                {/if}
            {/foreach}
            <input type="hidden" name="groupid[]" value="{$groupRs.id}">
            <div class="row mb-2">
                <div class="col-md-4 mt-2 pr-0 text-right">{$groupRs.title}：</div>
                <div class="col-md-5">
                    <div class="input-group">
                        <input name="discount[]" id="discount{$groupRs.id}" type="number" maxlength="10" class="form-control" value="{$discount}" onBlur="javascript:get_price(this.value,'#price',100);" />
                        <span class="input-group-append">
                            <span class="btn btn-default" onclick="upImage('#morepics1');">%</span>
                        </span>
                    </div>
                    <div class="text-0 h6 bold" id="discount{$groupRs.id}_tips"></div>
                </div>
            </div>
        {/volist}
        <div class="row mt-2 mb-2 text-center">
            <div class="col-md-12">
                <button type="button" id="discount_submit" class="btn btn-success h6 mr-4"><i class="fa fa-check-circle mr-2"></i>{:lang('v_save')}</button>
                <button type="button" class="btn btn-default h6" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times-circle mr-2"></i>{:lang('v_close')}</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
$('#discount_submit').click(function(){
    var price_reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
    {volist name="auth_group" id="groupRs"}
        if(!price_reg.test($('#discount'+{$groupRs.id}).val())){
            $('#discount'+{$groupRs.id}+'_tips').html('<i class="fa fa-info-circle fa-lg mr-2"></i>{:lang('g_illegal')}');
            return false;
        }else{
            $('#discount'+{$groupRs.id}+'_tips').html('');
        }
    {/volist}
    $.ajax({
        type: "POST",
        url: '{:url('/down/user_discount')}',
        dataType: "json",
        data: $('#group_discount').serialize(),
        success: function(data){
            switch(data){
                case 'success':
                    //操作成功
                    window.location.reload();
                    $.toast("<i class='fa fa-check-circle fa-lg mr-2'></i>{:lang('c_success')}",1000);
                    break;
                case 'error':
                    //操作失败
                    $.toast("<i class='fa fa-info-circle fa-lg text-danger mr-2'></i>{:lang('c_fail')}",1000);
                    break;
            }
        }
    });
});
</script>